package com.cube.dp.cor.wrapper;

import com.cube.dp.cor.context.TransformContext;
import com.cube.dp.cor.filter.DefaultTransformFilterChain;
import com.cube.dp.cor.filter.TransformFilter;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author cube.li
 * @date 2021/12/23 20:45
 * <p>
 * 包装后的TransformFilterChain
 */
public class WrappedTransformFilterChain extends DefaultTransformFilterChain {

    public WrappedTransformFilterChain(TransformContext context) {
        super(context);
    }

    @Override
    public void addTransformFilters(List<TransformFilter> sortedFilters) {
        throw new UnsupportedOperationException();
    }

    public <T extends TransformFilterWrapper> void addTransformFilterWrappers(List<T> filterWrappers) {
        getFilters().addAll(filterWrappers.stream().sorted(Comparator.comparingInt(TransformFilterWrapper::getOrder)).collect(Collectors.toList()));
    }
}
